package com.sm.healthy.data.bean

import android.os.Parcelable
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.Index
import androidx.room.PrimaryKey
import com.afollestad.date.year
import com.sm.healthy.ext.getTimeFormat
import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize
import java.util.*

/**
 * @description
 * @author csw
 * @date 2021-05-03
 */
@Parcelize
@Entity(tableName = "users", indices = [Index(value = ["id"], unique = true)])
data class UserEntity(
    //序号
    @PrimaryKey(autoGenerate = false) var uid: Long,
    var id: String = Calendar.getInstance().timeInMillis.getTimeFormat("yyyyMMddhhmmss"),
    var name: String = "",
    var sex: Byte = 0,//0 男， 1 女
    var birthday: String = "",//出生年月
    var mobile: String = "",//手机号
    var role: String = "",//角色
    var headerImg: Int = 0,//0老头 1老太 2男人 3女人 4男孩 5女孩 6无
) : Parcelable {
    @IgnoredOnParcel
    @Ignore
    val age: Int =
        Calendar.getInstance().year - (birthday.split("/").firstOrNull()?.toIntOrNull() ?: 0)

    @IgnoredOnParcel
    @Ignore
    val info: String = "$name $sexShow ${age}岁 $mobile"
    val sexShow
        get() = if (sex > 0) "女" else "男"


    fun uidShow(): String {
        return uid.toString()
    }

}